package Thread_Test;

/**
 * Created by asd73 on 2017/8/26.
 */
public class RunnableT {
    private int j;
    public static void main(String[] args) {
        RunnableT.Inc1 inc = new RunnableT().new Inc1();
        RunnableT.Dec1 dec1 =new RunnableT().new Dec1();
        for (int i=0;i<2;i++){
            Thread thread1 =new Thread(inc);
            thread1.start();
            Thread thread2 =new Thread(dec1);
            thread2.start();
        }
    }

    private synchronized void inc(){
        j++;
        System.out.println("+"+j);
    }

    private synchronized void dec(){
        j--;
        System.out.println("-"+j);
    }
    class Inc1 implements Runnable{
        @Override
        public void run() {
            for (int i=0;i<10;i++){
                inc();
            }
        }
    }

    class Dec1 implements Runnable{
        @Override
        public void run() {
            for (int i=0;i<10;i++){
                dec();
            }
        }
    }
}
